package pl.kosmowska.ewelina.client.app.activity.places;

import pl.kosmowska.ewelina.client.app.requestfactory.dto.LoanDataProxy;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
import com.google.web.bindery.requestfactory.shared.EntityProxyId;
import com.google.web.bindery.requestfactory.shared.RequestFactory;

public class LoanEditPlace extends Place {
	  
	  @Prefix("DodajZmienPozyczke")
	  public static class Tokenizer implements PlaceTokenizer<LoanEditPlace> {

	    private RequestFactory requestFactory;
	    
	    public Tokenizer(RequestFactory requestFactory) {
	      this.requestFactory = requestFactory;
	    }
	    	    
	    @Override
	    public String getToken(LoanEditPlace place) {
	      String s = "";
	      if (place.getLoanDataId() != null) {
	        s = requestFactory.getHistoryToken(place.getLoanDataId());
	      } else if (place.getLoanData() != null) {
	        s = requestFactory.getHistoryToken(place.getLoanData().stableId());
	      } else {
	        s = "new"; 
	      }
	      return s;
	    }

	    /**
	     * from - url activated
	     */
	    @Override
	    public LoanEditPlace getPlace(String token) {
	      EntityProxyId<LoanDataProxy> LoanDataId = null;
	      if (token == null || token.trim().length() == 0 || token.equals("new") == true) {
	        // new
	      } else {
	        LoanDataId = requestFactory.<LoanDataProxy> getProxyId(token);
	      }
	      return new LoanEditPlace(LoanDataId);
	    }

	  }
	     
	  /**
	   * from app place move
	   */
	  private LoanDataProxy LoanData;
	  
	  /**
	   * from url place move
	   */
	  private EntityProxyId<LoanDataProxy> LoanDataId;
	  
	  /**
	   * constructor - from app new place
	   */
	  public LoanEditPlace() {
	    this.LoanDataId = null;
	    this.LoanData = null;
	  }

	  
	  
	  /**
	   * constructor - from app place move
	   * @param walletData
	   */
	  public LoanEditPlace(LoanDataProxy LoanData) {
	    this.LoanDataId = null;
	    this.LoanData = LoanData;
	  }

	  /**
	   * constructor - from url move
	   * @param walletDataId
	   */
	  public LoanEditPlace(EntityProxyId<LoanDataProxy> LoanDataId) {
	    this.LoanDataId = LoanDataId;
	  }
	  

	  public EntityProxyId<LoanDataProxy> getLoanDataId() {
		    return LoanDataId;
		  }
	  
	  public LoanDataProxy getLoanData() {
		    return LoanData;
		  }
	 
	}


